{template 'common/header'}
<input type="hidden" name="storeid" value="{$storeid}" />
{php echo $this -> set_tabbar($action, $storeid);}
{if $operation == 'post'}
<div class="main">
	<form action="" method="post" class="form-horizontal form" enctype="multipart/form-data">
	<input type="hidden" name="parentid" value="{$parent['id']}" />
        <div class="panel panel-default">
            <div class="panel-heading">
                分类详细设置
            </div>
            <div class="panel-body">
                {if !empty($parentid)}
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">上级分类</label>
                    <div class="col-sm-9">
                        {$parent['name']}
                    </div>
                </div>
                {/if}
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">排序</label>
                    <div class="col-sm-9">
                        <input type="text" name="displayorder" class="form-control" value="{$category['displayorder']}" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">分类名称</label>
                    <div class="col-sm-9">
                        <input type="text" name="catename" class="form-control" value="{$category['name']}" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">分类描述</label>
                    <div class="col-sm-9">
                        <textarea name="description" class="form-control richtext" cols="70">{$category['description']}</textarea>
                    </div>
                </div>
            </div>
        </div>
        <div class="form-group col-sm-12">
            <input type="submit" name="submit" value="保存设置" class="btn btn-primary col-lg-1" />
            <input type="hidden" name="token" value="{$_W['token']}" />
        </div>
	</form>
</div>
{elseif $operation == 'display'}
<div class="main">
    <style>
        .form th {
            text-align: left;
            width: 15px;
            margin-right: 20px;
            overflow: hidden;
            float: none;
        }
    </style>
    <style>
        .form-control-excel {
            height: 34px;
            padding: 6px 12px;
            font-size: 14px;
            line-height: 1.42857143;
            color: #555;
            background-color: #fff;
            background-image: none;
            border: 1px solid #ccc;
            border-radius: 4px;
            -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
            box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
            -webkit-transition: border-color ease-in-out .15s,-webkit-box-shadow ease-in-out .15s;
            -o-transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
            transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
        }
    </style>
    <div class="panel panel-default" id="uploaddata" style="display: none;">
        <div class="panel-body">
            <form action="./index.php" method="post" class="form-horizontal form" onsubmit="return formcheck(this)"  enctype="multipart/form-data">
                <input type="hidden" name="leadExcel" value="true">
                <input type="hidden" name="c" value="site" />
                <input type="hidden" name="a" value="entry" />
                <input type="hidden" name="m" value="smart_ct" />
                <input type="hidden" name="do" value="UploadExcel" />
                <input type="hidden" name="ac" value="category" />
                <input type="hidden" name="storeid" value="{$storeid}" />
                <a class="btn btn-primary" href="javascript:location.reload()"><i class="fa fa-refresh"></i> 刷新</a>
                <input name="viewfile" id="viewfile" type="text" value="" style="margin-left: 40px;" class="form-control-excel" readonly>
                <a class="btn btn-primary"><label for="unload" style="margin: 0px;padding: 0px;">浏览...</label></a>
                <input type="file" class="pull-left btn-primary span3" name="inputExcel" id="unload" style="display: none;"
                       onchange="document.getElementById('viewfile').value=this.value;this.style.display='none';">
                <input type="submit" class="btn btn-primary" value="上传">
                <a class="btn btn-primary" href="../addons/smart_ct/example/example_category.xls">下载导入模板</a>
            </form>
        </div>
    </div>
    <div class="panel panel-default">
        <div class="panel-body">
            <form action="./index.php" method="post" class="form-horizontal form" onsubmit="return formcheck(this)"  enctype="multipart/form-data">
                <a class="btn btn-default" href="{php echo $this->createWebUrl('category', array('op' => 'post', 'storeid' => $storeid))}"><i class="fa fa-plus"></i> 添加分类</a>
                <a class="btn btn-success" href="#" onclick="$('#uploaddata').slideToggle();">批量导入</a>
            </form>
        </div>
    </div>
    <div class="panel panel-default">
        <div class="table-responsive panel-body">
        <form action="" method="post" class="form-horizontal form" >
            <input type="hidden" name="storeid" value="{$storeid}" />
            <table class="table table-hover">
                <thead class="navbar-inner">
                <tr>
                    <th style="width:5%;" class='with-checkbox'><input type="checkbox" class="check_all" /></th>
                    <th style="width:10%;">顺序</th>
                    <th style="width:5%;">ID</th>
                    <th style="width:70%;">分类名称</th>
                    <th style="width:10%;text-align:right;">操作</th>
                </tr>
                </thead>
                <tbody id="level-list">
                {loop $category $row}
                <tr>
                    <td class="with-checkbox"><input type="checkbox" name="check" value="{$row['id']}"></td>
                    <td><input type="text" class="form-control" name="displayorder[{$row['id']}]" value="{$row['displayorder']}"></td>
                    <td>{$row['id']}</td>
                    <td><div class="type-parent">{$row['name']}&nbsp;&nbsp;</div></td>
                    <td style="text-align:right;"><a class="btn btn-default btn-sm" href="{php echo $this->createWebUrl('category', array('op' => 'post', 'id' => $row['id'], 'storeid' => $storeid))}" title="编辑"><i class="fa fa-pencil"></i></a>&nbsp;&nbsp;<a class="btn btn-default btn-sm" href="{php echo $this->createWebUrl('category', array('op' => 'delete', 'id' => $row['id'], 'storeid' => $storeid))}" onclick="return confirm('确认删除此分类吗？');return false;" title="删除"><i class="fa fa-times"></i></a></td>
                </tr>
                {/loop}
                <tr>
                    <td colspan="5">
                        <input name="submit" type="submit" class="btn btn-primary" value="批量排序">
                        <input type="button" class="btn btn-primary" name="btndeleteall" value="批量删除" />
                        <input type="hidden" name="token" value="{$_W['token']}" />
                    </td>
                </tr>
                </tbody>
            </table>
        </form>
        {$pager}
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function(){
        $(".check_all").click(function(){
            var checked = $(this).get(0).checked;
            $("input[type=checkbox]").attr("checked",checked);
        });

        $("input[name=btndeleteall]").click(function(){
            var check = $("input[type=checkbox][class!=check_all]:checked");
            if(check.length < 1){
                alert('请选择要删除的分类!');
                return false;
            }
            if(confirm("确认要删除选择的分类?")){
                var id = new Array();
                check.each(function(i){
                    id[i] = $(this).val();
                });
                var url = "{php echo $this->createWebUrl('category', array('op' => 'deleteall', 'storeid' => $storeid))}";
                $.post(
                    url,
                    {idArr:id},
                    function(data){
                        alert(data.error);
                        location.reload();
                    },'json'
                );
            }
        });

    });
</script>
{/if}
{template 'common/footer'}